package com.linian.pushforcampus.mapper;

import com.linian.pushforcampus.domain.Vip;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VipMapper {

    @Insert("INSERT INTO vip (user_id, user_name, isVip, X_Id_Token, student_id, dataState, update_time, create_time,user_real_name ) " + "VALUES (#{userId}, #{userName}, #{isVip}, #{xIdToken}, #{studentId}, #{dataState}, #{updateTime}, #{createTime},#{userRealName})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertVip(Vip vip);

    @Select("SELECT * FROM vip WHERE id = #{id}")
    Vip getVipById(int id);

    /**
     * 查询vip状态不是-1的用户
     * @return
     */
    @Select("SELECT * FROM vip WHERE isVip != -1")
    List<Vip> getVipSurvive();

    @Select("SELECT * FROM vip")
    List<Vip> getAllVips();

    @Select("SELECT * FROM vip WHERE user_id LIKE CONCAT('%', #{userId}, '%')")
    List<Vip> getAllVipsForLike(String userId );

    @Select("SELECT * FROM vip WHERE dataState = 1 and isVip in (2,8)")
    List<Vip> getAllVipsByStates();

    @Update("UPDATE vip SET user_id = #{userId}, user_name = #{userName}, isVip = #{isVip}, " + "X_Id_Token = #{xIdToken}, student_id = #{studentId}, dataState = #{dataState}, " + "update_time = #{updateTime}, create_time = #{createTime},user_class = #{userClass},user_real_name=#{userRealName} " + "WHERE id = #{id}")
    void updateVip(Vip vip);

    @Delete("DELETE FROM vip WHERE id = #{id}")
    void deleteVip(int id);

    @Select("SELECT * FROM vip WHERE user_id = #{userId}")
    Vip getVipByUserIdFromUserID(String userId);
}